﻿using Moq;
using NUnit.Framework;
using SkiaSharp;
using System.Threading.Tasks;
using TabbedTemplate.Models;
using TabbedTemplate.Services;
using TabbedTemplate.ViewModels;

namespace UnitTest.NotTestViewModel
{
    public class TestDrawPicPageViewModel
    {

        /// <summary>
        /// 测试SaveCommand。
        /// </summary>
        /// <returns></returns>
        [Test]
        public async Task TestSaveCommand()
        {
            var imageServiceMock = new Mock<IImageService>();
            var mockImageService = imageServiceMock.Object;
            var alertServiceMock = new Mock<IAlertService>();
            var mockAlertService = alertServiceMock.Object;


            var drwaPicPageViewModel = new DrawPicPageViewModel(null, null,
                mockImageService, mockAlertService);
            await drwaPicPageViewModel.SaveCommandFunction();
            imageServiceMock.Verify(p =>
                p.SaveSanpImageToAlbumAsync(drwaPicPageViewModel.Image), Times.Once);
            alertServiceMock.Verify(p => p.ShowAlert("提示", "保存成功", "确定"), Times.Once);
        }

        [Test]
        public async Task TestDrawPicCommand()
        {
            var drawPicServiceMock = new Mock<IDrawPicService>();
            var sk = new SKEventArgsToReturn();
            var drawContent = new DrawContent();
            drawPicServiceMock
                .Setup(p => p.OnCanvasViewPaintSurface(sk, drawContent))
                .ReturnsAsync((SKImage)null);
            var mockDrawPicService = drawPicServiceMock.Object;
            var drawPicPageViewModel =
                new DrawPicPageViewModel(mockDrawPicService, null, null, null);
            drawPicPageViewModel.DrawContent = drawContent;

            await drawPicPageViewModel.DrawPicCommandFunction(sk);

            drawPicServiceMock.Verify(p => p.OnCanvasViewPaintSurface(sk, drawContent), Times.Once);
            Assert.IsTrue(drawPicPageViewModel.Image == null);
        }
    }
}
